package com.ly.hotel.spainterface.pp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.ly.hotel.R;
import com.ly.hotel.spainterface.pp.bean.PreItemBean;

import java.util.List;

/**
 * Created by mo on 2018/5/25.
 */

public class PpItemAdapter extends BaseAdapter {

    private Context context;
    private List<PreItemBean> itemBeans;
    private int defaultPosition = 0;

    public PpItemAdapter(Context context, List<PreItemBean> itemBeans) {
        this.context = context;
        this.itemBeans = itemBeans;
    }

    public void setDefaultPosition(int position) {
        this.defaultPosition = position;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return itemBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return itemBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder viewHolder = null;
        if (convertView == null) {
            view = LayoutInflater.from(context).inflate(R.layout.pp_js_xf_item, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.itemName = view.findViewById(R.id.item_name);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.itemName.setText(itemBeans.get(position).getName());
        if (defaultPosition == position) {
            viewHolder.itemName.setTextColor(ContextCompat.getColor(context, R.color.itemName));
        } else {
            viewHolder.itemName.setTextColor(ContextCompat.getColor(context, R.color.colorWhite));
        }
        return view;
    }

    class ViewHolder {
        TextView itemName;
    }
}
